<%--
  Created by IntelliJ IDEA.
  User: aaa
  Date: 2024/6/25
  Time: 23:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>我的任务</title>
</head>
<style>
    #content {
        border: black solid 5px;
        width: 1100px;
        height: 800px;
        margin-top: -280px;
        margin-left: 230px;
        color: grey;
        font-size: 50px;
    }

</style>
<body>
<div id="content">
    <table border="1" cellspacing="0" align="center" class="con-b" width="100%">
        <thead>
        <tr class="row" style="color: black;font-size: 25px">
            <c:if test="${session_newUser.getUserIdentify()!=0}">
                <td class="lf">学生姓名</td>
            </c:if>
            <td class="lf">题目</td>
            <td class="lf">答案</td>
            <td class="lf">是否完成</td>
            <td class="lf">分数</td>
            <c:if test="${session_newUser.getUserIdentify()==0}">
            <td class="lf">点击答题</td>
            </c:if>

            <c:if test="${session_newUser.getUserIdentify()==1}">
                <td class="lf">点击批改</td>
            </c:if>
            <td class="lf" colspan="2">操作</td>

        </tr>
        </thead>
        <tbody>
        <c:forEach items="${studentAnswerList}" var="Answer">
            <tr class="row" style="color: black;font-size: 25px">
                <c:if test="${session_newUser.getUserIdentify()!=0}">
                    <td class="lf">${Answer.userName}</td>
                </c:if>
                <td class="lf">${Answer.taskName}</td>
                <td class="lf">${Answer.studentAnswer}</td>
                <td class="lf">
                    <c:if test="${Answer.isFinish==0}">
                        未完成
                    </c:if>
                    <c:if test="${Answer.isFinish==1}">
                        未批改
                    </c:if>
                    <c:if test="${Answer.isFinish==2}">
                        完成
                    </c:if>
                </td>
                <td class="lf">${Answer.score}</td>
                <c:if test="${session_newUser.getUserIdentify()==0}">
                    <td class="lf"><button onclick="doAnswer('${Answer.taskAccount}','${Answer.isFinish}')">点击答题</button></td>
                </c:if>

                <c:if test="${session_newUser.getUserIdentify()==1}">
                    <td class="lf"><button onclick="doScore('${Answer.taskAccount}','${Answer.studentAccount}','${Answer.isFinish}')">点击批改</button></td>
                </c:if>


                <td><input type="button" value="删除"
                           onclick="deThisTask('${Answer.taskAccount}', '${Answer.studentAccount}','${Answer.isFinish}')">
                </td>

            </tr>
        </c:forEach>
        </tbody>
        <tr></tr>
    </table>
</div>
</body>
<script>
    function doScore(taskAccount,studentAccount,isFinish){
        //只有1的时候才代表可以完成未批改,才可以有批改的权限
        if(isFinish!=1){
            alter("暂时无批改权限")
            return;
        }
        //跳转并打开一个批改页面
        window.open("StudentServlet?action=doScore&taskAccount="+taskAccount+"&studentAccount="+studentAccount,null,"width=220,height=20,left=700,top=300");
    }



    function doAnswer(taskAccount,isFinish){
        if(isFinish!=0){
            alert("已作答!")
            return;
        }
        //为作答,跳转并打开做题页面
        window.open("StudentServlet?action=doAnswer&taskAccount="+taskAccount+"",null,"width=700,height=400,left=400,top=150");
    }

    function deThisTask(taskAccount, studentAccount, isFinish) {
        //1为老师用户
        if (${session_newUser.getUserIdentify()==1}) {
            //1代表学生已经完成了
            if (isFinish == 1) {
                alter("老师未批改,不能删")
            } else {
                //学生未完成此时可以删除,跳转并打开删除成功的页面
                window.location.href = "TeacherServlet?action=deleteTask&taskAccount=" + taskAccount + "&studentAccount=" + studentAccount + "&isFinish=" + isFinish
            }
        } else {
            //这里代表学生用户
            //2代表老师已经完成批改了,该任务就可以不用在学生用户中存在
            if (isFinish == 2) {
                window.location.href = "TeacherServlet?action=deleteTask&taskAccount=" + taskAccount + "&studentAccount=" + studentAccount + "&isFinish=" + isFinish
            } else {
                alter("任务正在进行,不能修改");
            }
        }
    }


</script>
</html>
